< previous page page_531 next page >

Page 531
When an error occurs in your Visual Basic program, the Err object properties are populated with the details of the error. You can inspect these values during your program execution and, if possible, use Visual Basic code to correct the error and continue the program.
For example, once an error occurs, you can inspect the properties of the object using the following code:
Msgbox "<" & CStr(Err.Number) & "> " & Err.Description & "[" & Err.Source & "]"
Once the error occurs and the Err object properties are updated, the Err object values do not change until another error is reported or the error-handling system is re-initialized.
Note.gif
The error handling system is re-initialized each time a procedure exit or end occurs, or when the special error-handling keywords Resume or On Error are executed. You learn more about these keywords later in this chapter.

If the error that was reported has an associated help file and help context ID, these properties are also filled in. You can use the HelpFile and HelpContext properties of the Err object to display an online help topic to explain the error condition to the user.
Tip.gif
Although help file composition and the construction of context-sensitive help is beyond the scope of a database book, Appendix B at the back of this book shows you how to create help files and how to link them to your Visual Basic programs.

If your application has called a dynamic-link library (DLL), you may be able to use the LastDLLError property of the Err object to get additional information about an error that occurred in a DLL. This property is only available on the 32-bit platform and may not be supported by the DLL you are calling.
Working with the Error Object and the Errors Collection
In addition to the built-in Err object, Visual Basic 5 also has a built-in Error object for database errors. This object is a child object of the DBEngine object. For this reason, you can only access the Error object if you have loaded a Microsoft data access object library (select Project | References from the main menu).

 
< previous page page_531 next page >

If you like this book, buy it!